home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
quintus
/
quintus0.lha
/
work
/
transform_2.06.2
< prev
next >
Wrap
Text File
|
1992-04-03
|
10KB
|
332 lines
%%%
%%% version 2.00.0
%%% initial version
%%% version 2.00.3
%%% added "outtreq" and "pullout_constants"
%%% version 2.00.4
%%% fixed input clause count when transforming equation
%%% version 2.00.5
%%% optimized equality transform by ordering literals in transformed clauses
%%% version 2.00.8
%%% added lexicographic path ordering
%%% version 2.01.3
%%% moved print_eq_trans to eq_trans
%%% version 2.01.4
%%% modified rewriting of equations according to David Plaisted's method
%%% version 2.01.8
%%% added transformed form of all non-input equations before hyper-linking
%%% version 2.02.0
%%% made the support and distance for pulled out equations the same as input
%%% version 2.02.2
%%% asserted pulled out equations at beginning of session
%%% deleted pulled out form when rewriting asserted clause
%%% version 2.02.5
%%% asserted equations along with pulled out forms at beginning of session
%%% asserted pulled out forms of equations at the beginning of each round
%%% version 2.03.4
%%% printed axioms
%%% version 2.04.2
%%% modified transform_equations_session and transform_equation_round include
%%% pulled out forms forms for input equations
%%% version 2.04.3
%%% when pulling out equations, ordered pulled out form so that pulled out
%%% literals for the smaller side with respect to path order come first
%%% removed transitivity axiom
%%% version 2.04.4
%%% no longer pull out equations at the beginning of rounds
%%% restored transitivity axiom
%%% version 2.04.5
%%% added restricted_rewrite to control whether restricted or unrestricted
%%% rewriting of equations is used
%%% added equality_transform_by_round flag
%%% when pulling out equations, ordered pulled out form so that pulled out
%%% literals for the larger side with respect to path order come first
%%% version 2.04.8
%%% improved efficiency of transform_equations_round
%%% version 2.05.1
%%% fixed transform_equations_round so that it works when neither
%%% fixed_priority nor slidepriority is specified
%%% version 2.05.2
%%% added clause splitting to transform_equations_round
%%% version 2.05.3
%%% added support for Quintus Prolog
%%% version 2.06.2
%%% added restricted_equality_transform
%%%
%%%
%%% Eq_trans performs the equality transformation on a set of literals.
%%% If the number of variables becomes too large, an error message is printed
%%% and the equality transform is not performed (the set of literals is simply
%%% returned).
%%%
eq_trans(Ls,Ls) :-
not(equality_transform),
!.
eq_trans(Ls1,Ls2) :-
eq_trans_1(Ls1,Ls2),
print_eq_trans(Ls1,Ls2),
!.
eq_trans_1([S=T],Ls) :-
orient_equation(S=T,S1=T1),
pullout_subterms([S1],Ss1),
pullout_subterms([T1],Ss2),
eq_trans_2(S1,Ss1,T1,Ss2,Ss3),
identical_delete_all_duplicates(Ss3,Ss4),
replace_subterms([S1=T1],Ss4,Ls1),
((restricted_equality_transform(N1), length(Ls1,N2), N2=<N1) -> (
reverse(Ls1,Ls)
); (
append(Ss1,Ss2,Ss5),
identical_delete_all_duplicates(Ss5,Ss6),
replace_subterms([S1=T1],Ss6,Ls2),
reverse(Ls2,Ls)
)),
vars_tail(Ls,V),
check_numbervars(V,
'Number of variables overflows in equality transform !'),
!.
eq_trans_1(Ls1,Ls2) :-
not(Ls1 = [S=T]),
pullout_subterms(Ls1,Ss1),
identical_delete_all_duplicates(Ss1,Ss2),
replace_subterms(Ls1,Ss2,Ls3),
vars_tail(Ls3,V),
check_numbervars(V,
'Number of variables overflows in equality transform !'),
sort_literals(Ls3,Ls2),
!.
eq_trans_1(Ls,Ls).
eq_trans_2(S1,Ss1,T1,Ss2,Ss3) :-
nonvar(S1),
check_pullout_constant(S1),
nonvar(T1),
check_pullout_constant(T1),
!,
append([S1|Ss1],[T1|Ss2],Ss3).
eq_trans_2(S1,Ss1,T1,Ss2,Ss3) :-
nonvar(S1),
check_pullout_constant(S1),
!,
append([S1|Ss1],Ss2,Ss3).
eq_trans_2(S1,Ss1,T1,Ss2,Ss3) :-
nonvar(T1),
check_pullout_constant(T1),
!,
append(Ss1,[T1|Ss2],Ss3).
eq_trans_2(S1,Ss1,T1,Ss2,Ss3) :-
append(Ss1,Ss2,Ss3).
%%%
%%% Eq_trans_np performs the equality transformation on a set of literals
%%% without printing the transformation even if outtreq is asserted.
%%%
eq_trans_np(Ls,Ls) :-
not(equality_transform),
!.
eq_trans_np(Ls1,Ls2) :-
eq_trans_1(Ls1,Ls2),
!.
%%%
%%% Pullout_subterms pulls out all appropriate subterms from a set of terms.
%%%
pullout_subterms([L],[]) :-
atomic(L),
!.
pullout_subterms([L],[]) :-
var(L),
!.
pullout_subterms(Ls,Ss) :- pullout_subterms(Ls,Ls,Ss).
pullout_subterms(Ls1,[not L|Ls2],Ss) :-
!,
pullout_subterms_args(Ls1,L,Ss1),
pullout_subterms(Ls1,Ls2,Ss2),
append(Ss1,Ss2,Ss),
!.
pullout_subterms(Ls1,[L|Ls2],Ss) :-
pullout_subterms_args(Ls1,L,Ss1),
pullout_subterms(Ls1,Ls2,Ss2),
append(Ss1,Ss2,Ss),
!.
pullout_subterms(_,[],[]).
pullout_subterms_1(Ls1,[L|Ls2],[L|Ss]) :-
nonvar(L),
check_pullout_constant(L),
!,
pullout_subterms_args(Ls1,L,Ss1),
pullout_subterms_1(Ls1,Ls2,Ss2),
append(Ss1,Ss2,Ss),
!.
pullout_subterms_1(Ls1,[L|Ls2],Ss) :-
pullout_subterms_args(Ls1,L,Ss1),
pullout_subterms_1(Ls1,Ls2,Ss2),
append(Ss1,Ss2,Ss),
!.
pullout_subterms_1(_,[],[]).
%%%
%%% Check_pullout_constant determines if a constant subterm should be pulled
%%% out.
%%%
check_pullout_constant(S) :-
not(atomic(S)),
!.
check_pullout_constant(_) :-
pullout_constants,
!.
%%%
%%% Pullout_subterms_arg pulls out all appropriate subterms from the arguments
%%% of a term.
%%%
pullout_subterms_args(Ls,T,Ss) :-
nonvar(T),
!,
T=..[_|As],
pullout_subterms_1(Ls,As,Ss),
!.
pullout_subterms_args(_,_,[]).
%%%
%%% Replace_subterms replaces a list of subterms in a set of literals.
%%%
replace_subterms(Ts,[],Ts).
replace_subterms(Ts1,[S|Ss],Ts2) :-
replace_subterm(Ts1,S,X,Ts3),
replace_subterm(Ss,S,X,Ss1),
replace_subterms([not S=X|Ts3],Ss1,Ts2),
!.
%%%
%%% Replace_subterm replaces a subterm in a set of terms.
%%%
replace_subterm([],_,_,[]).
replace_subterm([T|Ts1],S,X,[X|Ts2]) :-
T==S,
!,
replace_subterm(Ts1,S,X,Ts2).
replace_subterm([T1|Ts1],S,X,[T2|Ts2]) :-
replace_subterm_args(T1,S,X,T2),
replace_subterm(Ts1,S,X,Ts2).
%%%
%%% Replace_subterm_args replaces a subterm in the arguments of a term. If the
%%% term has no arguments, the term is not modified.
%%%
replace_subterm_args(T1,S,X,T2) :-
nonvar(T1),
!,
T1=..[F|As1],
replace_subterm(As1,S,X,As2),
T2=..[F|As2],
!.
replace_subterm_args(T,_,_,T).
%%%
%%% Sort_literals sorts a set of literals into ascending order with respect to
%%% recursive path ordering taking negative literals to be larger than positive
%%% literals. The order of equivalentl literals is unspecified.
%%%
sort_literals([],[]).
sort_literals([L|Ls1],Ls2) :-
sort_literals(Ls1,Ls3),
sort_literals_1(L,Ls3,Ls2),
!.
sort_literals_1(L1,[L2|Ls1],[L2|Ls2]) :-
sort_literals_2(L1,L2),
!,
sort_literals_1(L1,Ls1,Ls2).
sort_literals_1(L,Ls,[L|Ls]).
sort_literals_2(not L1,not L2) :-
!,
order_term(L1,>,L2),
!.
sort_literals_2(not L1,L2) :- !.
sort_literals_2(L1,not L2) :-
!,
fail.
sort_literals_2(L1,L2) :-
!,
order_term(L1,>,L2),
!.
%%%
%%% Assert the equality axioms.
%%%
assert_eq_axioms(N,N) :-
not(equality_transform),
!.
assert_eq_axioms(N1,N2) :-
semi_internal_form([X=X],C1),
assertz(sent_C(C1)),
semi_internal_form([Y=Z,not X=Y,not X=Z],C2),
assertz(sent_C(C2)),
write_line(5,'equality axioms:'),
write_line(10,'[X=X]'),
write_line(10,'[Y=Z,not X=Y,not X=Z]'),
N2 is N1+2,
!.
%%%
%%% Print_eq_trans prints an equality transformation.
%%%
print_eq_trans(_,_) :-
not(outtreq),
!.
print_eq_trans(C1,C2) :-
write_line(10,'equality transformation:'),
not(not(print_eq_orig(C1))),
not(not(print_eq_trans(C2))),
!.
print_eq_orig(C) :-
vars_tail(C,V),
var_list(V),
write_line(13,'orig: ',C),
!.
print_eq_trans(C) :-
vars_tail(C,V),
var_list(V),
write_line(13,'trans: ',C),
!.
%%%
%%% Transform_equations_round asserts the transformed equations at the
%%% beginning of a round.
%%%
transform_equations_round :-
equality_transform,
equality_transform_by_round,
!,
cputime(TT1),
transform_equations_round_1,
split_clauses,
cputime(TT2),
TT3 is TT2 - TT1,
write_line(5,'Equation transform(s): ',TT3),
!.
transform_equations_round.
transform_equations_round_1 :-
sent_C(cl(_,_,by([S=T],V1a,V1a,_,_),_,sp(S1,_,_),_,_,_,_)),
eq_trans([S=T],C1),
vars_tail(C1,V),
clause_size(C1,CSize),
not(duplicate_clause_C(CSize,C1,V)),
!,
linearize_term(C1,C2,V1,V2),
vars_literals(C1,W),
compute_V_lits(W,0,NLits),
set_sr_status(S1,C2,Sp,Ds),
list_of_Ns(C2,0,Dis),
calculate_priority_clause(C2,Sp,Ds,Pr),
transform_equations_round_2(Pr),
assertz(sent_C(cl(CSize,NLits,by(C2,V1,V2,V,W),0,Sp,Ds,0,Dis,Pr))),
fail.
transform_equations_round_1.
transform_equations_round_2(Pr) :-
priority_bound(PrioBound),
!,
check_prioritybound(Pr,PrioBound),
!.
transform_equations_round_2(_).